package com.macro.mall.portal.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.portal.domain.Appraisal;
import com.macro.mall.portal.domain.Transfer;
import com.macro.mall.portal.domain.vo.PageVo;
import com.macro.mall.portal.service.IAppraisalService;
import com.macro.mall.portal.service.impl.AppraisalServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/appraisal")
@Api(tags = "AppraisalController", description = "估价")
public class AppraisalController {

    @Autowired
    private IAppraisalService appraisalService;

    private static Map<String, Object> cacheMap = new HashMap<String, Object>();

    static {
        cacheMap.put("room", 38177);
    }


    @ApiOperation("添加估价记录")
    @RequestMapping(value = "/addOne", method = RequestMethod.POST)
    public CommonResult addOne(@RequestBody Appraisal appraisal) {
        try {
            appraisalService.addOne(appraisal);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("服务器异常");
        }
        return CommonResult.success(null, "添加成功");
    }

    @ApiOperation("分页查询记录")
    @RequestMapping(value = "/query", method = RequestMethod.POST)
    public CommonResult query(@RequestBody PageVo page) {
        IPage<Appraisal> appraisalIPage = null;
        try {
            appraisalIPage = appraisalService.selectBy(page.getOpenId(), page.getPage(), page.getSize());
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("服务器异常");
        }
        return CommonResult.success(appraisalIPage);
    }

    @ApiOperation("查询房产人数")
    @RequestMapping(value = "/selectPerson", method = RequestMethod.POST)
    public CommonResult selectPerson() {
        //38177
        try {
            int max = 3, min = 1;
            long randomNum = System.currentTimeMillis();
            int ran3 = (int) (randomNum % (max - min) + min);
            cacheMap.put("room", (int) cacheMap.get("room") + ran3);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("服务器异常");
        }
        return CommonResult.success(cacheMap);
    }
}
